﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Aliyun.OSS.Sdk.JSST;

namespace AliyunOssSdkJSSTTest
{
    class Program
    {
        static void Main(string[] args)
        {

            Console.WriteLine("Aliyun SDK for .NET Samples!");

            string BucketName = "syxoss2";
            //const string BucketName = "publicdata"; 
            //const string BucketName = "jhtoss1";//"publicdata"; 


            string Folder = "g3test/";//虚拟文件夹


            string AccessKeyId = "LTAIEZVrzbudXZFL";
            //const string AccessKeyId ="LTAIS8N6dUnTV2sS";
            //const string AccessKeyId ="LTAIwGSC73VqeE92"; //"LTAIS8N6dUnTV2sS";

            string AccessKeySecret = "vR6RACgHB8MT54EXEi6tosq51btDVn";
            //const string AccessKeySecret ="pFSVugeZyj6ecpH1u7YejlWtWWsUvN";
            //const string AccessKeySecret =//"eV9GKWZekUIhdLf2yg6GNSjeuSDdx9";

            string Endpoint = "oss-cn-shenzhen.aliyuncs.com";
            //const string Endpoint = "oss-cn-hangzhou.aliyuncs.com";
            //const string Endpoint = //"oss-cn-shenzhen-internal.aliyuncs.com";


            Config.Ini(AccessKeyId, AccessKeySecret, Endpoint, BucketName);

            try
            {
                //string fileToUpload = @"E:\lisheng\Framework\OSSPicUpdate\FileToUpload\SB.JPG";
                string fileToUpload = @"E:\pic\Jellyfish.jpg";
                string key = Folder + DateTime.Now.ToString("yyyyMMddHHmmss") + "/GUID/" + fileToUpload.Substring(fileToUpload.LastIndexOf('\\') + 1);
                Result r =new Result();
                int intResult = PutObjectHelp.PutObjectFromFile(key, fileToUpload, out r);
                //上传成功
                if (r.Status == 0)
                {
                    Console.WriteLine("PutObjectFromFile succeeded. ");
                    //示例：如您在Region为华东1，Bucketname为abc，Object为myfile/aaa.txt，那么您的外网访问地址为：
                    //abc.oss-cn-hangzhou.aliyuncs.com/myfile/aaa.txt
                    string strUrl = string.Format("外网访问地址为：https://{0}.{1}/{2}", BucketName, Endpoint, key);

                    Console.WriteLine(strUrl);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Failed with error info: {0}", ex.Message);
            }

            Console.WriteLine("Press any key to continue . . . ");
            Console.ReadKey(true);
        }
    }
}
